const Service = require('egg').Service;
class DzfService extends Service {
    async dzfzuoping() {
        const sql = `select * from opus left join opus1user on opus.id = opus1user.opusid left join user on user.id = opus1user.userid limit 6`
        const data = await this.app.mysql.query(sql);
        // console.log(sql, 222222);
        return data;
    }
    async more(start) {
        const sql = `select * from opus left join opus1user on opus.id = opus1user.opusid left join user on user.id = opus1user.userid limit ${start},6`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async motai(opus) {
        const sql = `SELECT * FROM opus left join opus1user on opus.id = opus1user.opusid left join user on user.id = opus1user.userid WHERE opusid=${opus}`
        const data = await this.app.mysql.query(sql);
        return data;
    }

    // 点赞作品

    async addZan(opusid, userid) {
        const sql1 = `SELECT * FROM good1opus WHERE opusid=${opusid} and userid =${userid}`
            // const sql = `insert into good1opus (opusid,userid) values (${opusid},${userid})`
        const data = await this.app.mysql.query(sql1);
        return data;
    }
    async addZan1(opusid, userid) {
        const sql = `insert into good1opus (opusid,userid) values (${opusid},${userid})`
        const data = await this.app.mysql.query(sql);
        return data;
    }

    //关注作者

    async follow(fans, star) {
        const sql = `SELECT * FROM follow WHERE fans=${fans} AND star=${star}`
            // const sql = `insert into follow (fans, star) values (${fans},${star})`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async follow1(fans, star) {
        const sql = `insert into follow (fans, star) values (${fans},${star})`
        const data = await this.app.mysql.query(sql);
        return data;
    }

    // 评论
    async comments(opusid) {
        const sql = `select * from comment left join opus1comment on comment.id = opus1comment.commentid left join opus on opus.id = opus1comment.opusid left join comment1user on comment.id = comment1user.userid left join user on user.id = comment1user.userid where opus.id=${opusid} `
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async dianzan(opusid) {
            const sql = `SELECT touxiang FROM user LEFT JOIN good1opus ON good1opus.userid = user.id WHERE good1opus.opusid=${opusid} limit 14`
                // console.log(sql, 3333333333);
            const data = await this.app.mysql.query(sql);

            return data;
        }
        // 点击更多获取点击量
    async moredianzan(opusid, length) {
        const sql = `SELECT touxiang FROM user LEFT JOIN good1opus ON good1opus.userid = user.id WHERE good1opus.opusid=${opusid} limit ${length},500`
            // console.log(sql, 4444444444);
        const data = await this.app.mysql.query(sql);
        return data;
    }

    async qitawork(userid) {
        const sql = `select img FROM opus1user inner join user on user.id = opus1user.userid inner join opus on opus.id = opus1user.opusid WHERE user.id=${userid} LIMIT 9`
        const data = await this.app.mysql.query(sql);
        return data;
    }

    async qitacaipu(userid) {
        const sql = `select img FROM cook1user inner join user on user.id = cook1user.userid inner join cook on cook.id = cook1user.cookid WHERE user.id=${userid} LIMIT 9`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async guanzhu(userid) {
            const sql = `SELECT * FROM follow WHERE star=${userid}`
            const data = await this.app.mysql.query(sql);
            return data;
        }
        // 注册，是否已登录
    async ishave(res) {
            const sql = `SELECT * FROM user WHERE email="${res.email}"`
            const data = await this.app.mysql.query(sql);
            return data;
        }
        // 登录中账号密码是否匹配
    async login(res) {
        const sql = `SELECT * FROM user WHERE email="${res.email}"AND pwd="${res.pwd}"`
        const data = await this.app.mysql.query(sql);
        return data;
    }
}
module.exports = DzfService;